var JVUserTools = new Class({

    initialize: function(options){
		var userPanel = $('newsletterform');
        var userPanels = $('userpanels');
		if(!userPanel) return;
		var userPanelCoord = userPanel.getCoordinates();
		var isShowed = false, offsetW = 3;
	    var isRTL = $$('body')[0].hasClass('rtl');
        if(isRTL){
            var userPanelFx = new Fx.Morph(userPanels).set({'left': -userPanelCoord.width - offsetW});
        }
        else{
            var userPanelFx = new Fx.Morph(userPanels).set({'right': -userPanelCoord.width - offsetW});        
        }

    	$('toggle').addEvent('click', function(e){
			e = new Event(e).stop();	
			isShowed = !isShowed;
            if(isRTL){
                userPanelFx.start({'left': isShowed ? 0 : -userPanelCoord.width - offsetW});
            }
            else{
            	userPanelFx.start({'right': isShowed ? 0 : -userPanelCoord.width - offsetW});
            }		
		});	        
       
	    var labels = userPanel.getElements('.layouttype .list label');    
        var label2 = userPanel.getElements('.temp_color .list label');
            
		labels.each(function(labelTag){
			labelTag.addEvent('click', function(){
				labels.removeClass('active');	
				this.addClass('active');
                this.getPrevious().checked = true;	
			});
		});
       
		label2.each(function(labelTag){
			labelTag.addEvent('click', function(){
				label2.removeClass('active');	
				this.addClass('active');
                this.getPrevious().checked = true;	
			});
		});
		

		var resetBtn = userPanel.getElement('input[type=reset]');
        var applyBtn = userPanel.getElement('input[type=submit]');
        
        if(resetBtn){

          	resetBtn.addEvent('click', function(){
                for(var i = 0; i < userPanel.elements.length; i++)
                {
                    if(userPanel.elements[i].checked && userPanel.elements[i].type == 'radio' || userPanel.elements[i].type != 'radio'){
                        if(userPanel.elements[i].value != 'Apply' && userPanel.elements[i].value != 'Reset'){
                            Cookie.dispose(userPanel.elements[i].name);
                        }
                    }                    
                } 
                 window.location = window.location;    
            });
        }
        



        if(applyBtn){
          	applyBtn.addEvent('click', function(){
                for(var i = 0; i < userPanel.elements.length; i++)
                {
                    if(userPanel.elements[i].checked && userPanel.elements[i].type == 'radio' || userPanel.elements[i].type != 'radio'){
                        if(userPanel.elements[i].value != 'Apply' && userPanel.elements[i].value != 'Reset'){ 
                            Cookie.write(userPanel.elements[i].name,userPanel.elements[i].value);
                        }
                    }
                } 

                 window.location = window.location;    
            });
        }
    },    
    
    changeVersion: function(theme,version){
        Cookie.write(theme+'_version',version);
        window.location = window.location;   
    },
    
    showSearch: function(itemid){
        var search  = $('mobileSearch');
        var display = search.getStyle('display');
        search.setStyle('display', display == 'block' ? 'none' : 'block');    
        
      	
        
    } 
      
});

var JVUserTools;
		
window.addEvent('domready',function(){	
	JVUserTools = new JVUserTools();

});